import http from '../http';

// 商品品牌接口类型定义
export interface Brand {
  id?: number;
  name: string;
  logo?: string;
  description?: string;
  website?: string;
  sortOrder: number;
  isShow: number;
  createdAt?: string;
  updatedAt?: string;
}

export interface BrandListParams {
  page?: number;
  pageSize?: number;
  keyword?: string;
  isShow?: number;
}

export interface BrandListResponse {
  list: Brand[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}

export interface BrandStats {
  total: number;
  show: number;
  hide: number;
}

export class BrandApi {
  /**
   * 创建商品品牌
   */
  createBrand(data: Omit<Brand, 'id' | 'createdAt' | 'updatedAt'>) {
    return http.post('/api/brands', data);
  }

  /**
   * 获取品牌列表
   */
  getBrandList(params: BrandListParams = {}) {
    return http.get<{
      code: number;
      message: string;
      data: BrandListResponse;
    }>('/api/brands', { params });
  }

  /**
   * 获取品牌详情
   */
  getBrandDetail(id: number) {
    return http.get<{
      code: number;
      message: string;
      data: Brand;
    }>(`/api/brands/${id}`);
  }

  /**
   * 更新品牌
   */
  updateBrand(id: number, data: Partial<Brand>) {
    return http.put(`/api/brands/${id}`, data);
  }

  /**
   * 删除品牌
   */
  deleteBrand(id: number) {
    return http.delete(`/api/brands/${id}`);
  }

  /**
   * 批量删除品牌
   */
  batchDeleteBrands(ids: string[]) {
    return http.post('/api/brands/batch-delete', { ids });
  }

  /**
   * 更新品牌状态
   */
  updateBrandStatus(id: number, isShow: number) {
    return http.patch(`/api/brands/${id}/status`, { isShow });
  }

  /**
   * 获取品牌统计数据
   */
  getBrandStats() {
    return http.get<{
      code: number;
      message: string;
      data: BrandStats;
    }>('/api/brands/stats');
  }

  /**
   * 获取所有可见品牌
   */
  getAllVisibleBrands() {
    return http.get<{
      code: number;
      message: string;
      data: Brand[];
    }>('/api/brands/visible');
  }
}

// 导出实例
export const brandApi = new BrandApi();